﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair.kucunpandian
{
    public partial class frmpdxz : Form
    {
        public frmpdxz()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(constr);
            try
            {
                conn.Open();
                for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
                {
                    int spid = Int32.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
                    string spname = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    decimal spkc = decimal.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                    string sql = string.Format("INSERT INTO [BHairDB].[dbo].[pdxz] ([spid],[spname],[spkc],[pdkc])VALUES({0},'{1}','{2}','0')", spid, spname, spkc);
                    SqlCommand comm = new SqlCommand(sql,conn);
                    comm.ExecuteNonQuery();
                }
                this.Close();
            }
            catch (Exception ex){ MessageBox.Show(ex.Message); }
        }

        private void frmpdxz_Load(object sender, EventArgs e)
        {
            selectall();
        }
        #region 查询所有商品
        public void selectall()
        {
            try
            {
                SqlConnection conn = new SqlConnection(constr);
                conn.Open();
                string sql = "SELECT [iid] as 商品编号,[iname] as 商品名称,[iamount] as 商品库存 FROM [BHairDB].[dbo].[items] where jc!=2";
                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                this.dataGridView1.DataSource = dt;
                conn.Close();
            }
            catch
            {

            }
        }
        #endregion
    }
}
